<template>
<div>
  <div class="box">
    <h1>表单提交</h1>
    <form action="" @submit.prevent="post_data">
      <input placeholder="用户名" v-model="form_data.username" class="inp" type="text" name="" id=""><br>
      <input placeholder="密码" v-model="form_data.password" class="inp" type="password" name="" id=""><br>
      <input placeholder="邮箱" v-model="form_data.e_mail" class="inp" type="text" name="" id=""><br>
      <label for="">性别：</label>
      <label for="">男</label>
      <input class="check" type="radio" value="男" v-model="form_data.sex" name="sex" id="">
      <label for="">女</label>
      <input class="check" type="radio" value="女" v-model="form_data.sex" name="sex" id=""><br>
      <label for="">兴趣爱好：</label>
      <label for="">篮球</label>
      <input v-model="form_data.hobby" class="check" type="checkbox" name="" value="篮球" id="">
      <label for="">足球</label>
      <input v-model="form_data.hobby" class="check" type="checkbox" name="" value="足球" id="">
      <label for="">羽毛球</label>
      <input v-model="form_data.hobby" class="check" type="checkbox" name="" value="羽毛球" id=""><br>
      <button class="sub">提交</button>
    </form>
  </div>
  <div class="table_box">
    <table>
      <thead>
        <td>{{table_head.thead_name}}</td>
        <td>{{table_head.thead_password}}</td>
        <td>{{table_head.thead_e_mail}}</td>
        <td>{{table_head.thead_sex}}</td>
        <td>{{table_head.thead_hobby}}</td>
        <td>{{table_head.thead_remove}}</td>
      </thead>
      <tr v-for="(item,index) of table_data" :key="index">
        <td>{{item.username}}</td>
        <td>{{item.password}}</td>
        <td>{{item.e_mail}}</td>
        <td>{{item.sex}}</td>
        <td>{{item.hobby}}</td>
        <td>
          <button @click="table_del" class="del">删除</button>
        </td>
      </tr>
    </table>
  </div>
</div>
</template>

<script>
export default {
  data(){
    return{
      form_data:{
        username:"",
        password:"",
        e_mail:"",
        sex:"",
        hobby:[]
      },
      table_head:{
        thead_name:"用户名",
        thead_password:"密码",
        thead_e_mail:"邮箱",
        thead_sex:"性别",
        thead_hobby:"爱好",
        thead_remove:"编辑",
      },
      table_data:[
        {
          username:"aa",
          password:"11",
          e_mail:"222",
          sex:"男",
          hobby:["篮球"]
        },
      ]
    }
  },
  methods:{
    post_data(){
      console.log(this.form_data);
      this.table_data.push(this.form_data)
    console.log(this.table_data)
    this.form_data = {
          username:"",
          password:"",
          e_mail:"",
          sex:"",
          hobby:[]
        }
    },
    table_del(index){
      this.table_data.splice(index,1)
    }
  },
  filters:{

  }
}
</script>

<style>
  *{
    margin: 0;
    padding: 0;
  }
  .table_box{
    height: 550px;
    width: 1152px;
    overflow: auto;
    float: right;
    margin-right: 100px;
  }
  thead{
    font-weight: bolder;
  }
  tr,thead{
    display: block;
    border-bottom: 1px solid rgb(175, 175, 175);
  }
  td{
    /* width: 10%; */
    text-align: center;
    /* border:1px solid #000; */
    font-size: 16px;
    width: 192px;
    height: 46px;
    line-height: 46px;
    text-align: center;
    margin: 0 auto;
  }
  .del{
    width: 50px;
    height: 30px;
    border: none;
    background-color: rgb(116, 116, 116);
    color: #fff;
    border-radius: 5px;
  }
  .box{
    width: 500px;
    height: 550px;
    /* border: 1px solid #000; */
    margin: 10px;
    float: left;
    background-color: rgb(116, 116, 116);
    overflow: hidden;
  }
  h1{
    color: #fff;
    text-align: center;
    margin-top: 20px;
  }
  .box .inp{
    width: 400px;
    height: 60px;
    margin-top: 10px;
    margin-left: 40px;
    border: none;
    padding-left: 10px;
    outline: none;
    /* float: right; */
  }
  .box .inp:first-child{
    margin-top: 20px;
  }
  .box label{
    color: #fff;
    margin-left: 40px;
    line-height: 60px;
  }
  .check{
    width: 20px;
    height: 20px;
    margin-left: 10px;
  }
  .sub{
    width: 400px;
    height: 60px;
    background-color: #fff;
    color: #000;
    border: none;
    margin-left: 40px;
    margin-top: 20px;
    outline: none;
  }
</style>
